import request from './request'

// 用户相关接口
export const userApi = {
  // 登录
  login: (data) => {    
    return request({
      url: '/users/login',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: {
        phone: data.username,
        pwd: data.password
      }
    })
  },
  
  // 获取用户信息
  getUserInfo: () => {
    const token = uni.getStorageSync('token')
    console.log('获取到的token:', token)
    return request({
      url: `/users/${token}`,  // 使用token作为URL参数
      method: 'GET'
    })
  },
  
  // 获取用户积分
  getUserScore: (t_id) => {
    return request({
      url: `/customerInfo/score?t_id=${t_id}`,  // 将参数放在URL中
      method: 'GET'
    })
  },
  
  // 修改密码
  changePassword: (data) => {
    return request({
      url: '/user/password',
      method: 'PUT',
      data
    })
  },

  // 检查用户角色
  checkRole: (userId) => {
    return request({
      url: '/users/roleCheck',
      method: 'POST',
      data: userId
    })
  }
}

// 菜品相关接口
export const dishApi = {
  // 获取菜品列表
  getDishList: () => {
    return request({
      url: '/dishes/list',
      method: 'GET'
    })
  },
  
  // 获取菜品分类
  getDishTypes: () => {
    return request({
      url: '/dishes/types',
      method: 'GET'
    })
  },

  // 添加菜品分类
  addDishType: (name) => {
    return request({
      url: `/dishes/types/add?dt=${encodeURIComponent(name)}`,
      method: 'POST'
    })
  },

  // 更新菜品分类
  updateDishType: (id, name) => {
    return request({
      url: `/dishes/types/upd?dt=${id}&name=${encodeURIComponent(name)}`,
      method: 'POST'
    })
  },

  // 删除菜品分类
  deleteDishType: (id) => {
    return request({
      url: `/dishes/types/del?dtId=${id}`,
      method: 'GET'
    })
  },

  // 获取所有菜品（包含分类信息）
  getAllDishes: () => {
    return request({
      url: '/dishesDTO/list',
      method: 'GET'
    })
  },

  // 更新菜品状态
  updateDishStatus: (dishId, status) => {
    // 将数字状态转换为对应的枚举名称
    const statusMap = {
      0: 'SELL',
      1: 'SOLD_OUT',
      2: 'TAKEN_OFF_THE_SHELVES'
    };
    const statusEnum = statusMap[status];
    if (!statusEnum) {
      throw new Error('无效的状态值');
    }
    return request({
      url: `/dishes/${dishId}/status?status=${statusEnum}`,
      method: 'PUT',
      data: {}
    })
  },
  
  // 退菜
  returnDish(orderId, dishId) {
    return request({
      url: `/dishes/return?orderId=${orderId}&dishId=${dishId}`,
      method: 'POST'
    })
  },
  
  // 创建菜品
  createDish(data) {
    return request({
      url: '/dishes',
      method: 'POST',
      data
    })
  },

  // 更新菜品信息
  updateDish(dishId, data) {
    return request({
      url: `/dishes/${dishId}`,
      method: 'PUT',
      data
    })
  }
} 

// 区域相关接口
export const regionApi = {
  // 获取区域列表
  getRegions: (regionIds) => {
    const queryString = regionIds.map(id => `regionIds=${id}`).join('&')
    return request({
      url: `/region?${queryString}`,
      method: 'GET'
    })
  }
}

// 餐桌相关接口
export const boardApi = {
  getBoardById: (boardId) => {
    return request({
      url: `/board/${boardId}`,
      method: 'GET'
    })
  },
  // 获取餐桌列表
  getBoards: (regionIds) => {
    const queryString = regionIds.map(id => `regionIds=${id.toString()}`).join('&')
    return request({
      url: `/board?${queryString}`,
      method: 'GET'
    })
  },
  // 更换餐桌
  changeBoard: (boardId, orderId) => {
    return request({
      url: `/board/change?boardId=${boardId}&orderId=${orderId}`,
      method: 'POST'
    })
  },
  // 修改餐桌状态
  updBoard: (board) => {
    return request({
      url: '/board/upd',
      method: 'POST',
      data: board
    })
  }
}

// 订单相关接口
export const orderApi = {
  // 获取订单列表
  getOrderList: (t_id) => {
    return request({
      url: `/ordersDTO/orderDto?t_id=${t_id}`,
      method: 'GET'
    })
  },
  // 获取区域订单列表
  getRegionOrders: (regionIds) => {
    const queryString = regionIds.map(id => `regionIds=${id.toString()}`).join('&')
    return request({
      url: `/orders/region?${queryString}`,
      method: 'GET'
    })
  },
  
  // 获取订单详情
  getOrderInfo: (orderId) => {
    return request({
      url: `/orders/${orderId}/items`,
      method: 'GET'
    })
  },
  
  // 获取订单项列表
  getOrderItems: (orderId) => {
    return request({
      url: `/orders/${orderId}/items`,
      method: 'GET'
    })
  },
  
  // 获取订单状态
  getOrderStatus: (orderId) => {
    return request({
      url: `/orders/${orderId}/status`,
      method: 'GET'
    })
  },
  
  // 更新订单状态
  updateOrderStatus(orderId, status) {
    return request({
      url: `/orders/${orderId}/status?orderStatus=${status}`,
      method: 'PUT'
    })
  },
  
  // 创建订单
  createOrder: (data) => {
    return request({
      url: '/orders',
      method: 'POST',
      data
    })
  },
  
  // 创建订单项
  createOrderItem: (orderId, dishId, quantity) => {
    return request({
      url: `/customerItem/${dishId}?orderId=${orderId}&dishId=${dishId}&quantity=${quantity}`,
      method: 'GET'
    })
  },
  
  // 取消订单
  cancelOrder: (orderId) => {
    return request({
      url: `/orders/${orderId}/cancel`,
      method: 'POST'
    })
  },
  
  // 批量获取订单项
  getOrderItemsBatch: (orderIds) => {
    return request({
      url: '/orders/items/batch',
      method: 'POST',
      data: {
        orderIds
      }
    })
  },
  
  // 获取指定日期的订单信息
  getOrdersByDate: (date) => {
    return request({
      url: date ? `/orders/date?date=${date}` : '/orders/date',
      method: 'GET'
    })
  },
  updBoard: (board) => {
    return request({
      url: '/board/upd',
      method: 'POST',
      data: board
    })
  }
} 

// 优惠券相关接口
export const couponApi = {
  getCouponListByUserId: (uId) => {
    return request({
      url: `/coupons/coupon-user/${uId}`,
      method: 'GET'
    })
  },
  getCouponList: () => {
    return request({
      url: '/coupons/couponInfo',
      method: 'GET'
    })
  },
  createCoupon: (data) => {
    return request({
      url: '/coupons',
      method: 'POST',
      data
    })
  },
  updateCoupon: (data) => {
    return request({
      url: '/coupons/update',
      method: 'POST',
      data
    })
  }
} 

// 我的相关接口
export const mineApi = {
  // 获取我的信息
  getMyInfo: (t_id) => {
    return request({
      url: `/mineDTO/info?t_id=${t_id}`,
      method: 'GET'
    })
  }
} 

export const selfCheckApi = {
  getSelfCheckList: (year, month, storeId) => {
    return request({
      url: `/self-inspections/list/${storeId}`,
      method: 'GET',
      data: {
        year,
        month
      }
    })
  },
  getSelfCheckImage: (siId) => {
    return request({
      url: `/inspect-image/image/${siId}`,
      method: 'GET'
    })
  },
  submitSelfCheck: (data) => {
    return request({
      url: '/inspect-image/submit',
      method: 'POST',
      data
    })
  },
  uploadImage: (data) => {
    return request({
      url: '/inspect-image/upload',
      method: 'POST',
      data
    })
  }
}

// 测试数据 - 用于直接获取分类和菜品数据
export const testData = {
  // 分类数据
  categories: {
    "code": 200, 
    "message": null, 
    "data": [
      {"dtId":1,"dtName":"热门"},
      {"dtId":2,"dtName":"冷菜"},
      {"dtId":3,"dtName":"热菜"},
      {"dtId":4,"dtName":"汤品"},
      {"dtId":5,"dtName":"主食"},
      {"dtId":6,"dtName":"甜品"},
      {"dtId":7,"dtName":"酒水饮料"}
    ]
  },
  
  // 菜品数据
  dishes: {
    "code":200,
    "message":null,
    "data":[{"dishId":1,"dishImage":"dish01.jpg","dishName":"海蜇皮拌黄瓜","price":38.00,"dishStatus":0,"dtId":1,"dishDescribe":"海蜇皮爽脆，黄瓜清新，搭配特制酱汁，口感爽口开胃。"},{"dishId":2,"dishImage":"dish02.jpg","dishName":"海带丝拌虾仁","price":42.00,"dishStatus":0,"dtId":1,"dishDescribe":"海带丝富含营养，虾仁鲜美，搭配清新的调料，营养又美味。"},{"dishId":3,"dishImage":"dish03.jpg","dishName":"冰镇海参","price":68.00,"dishStatus":0,"dtId":1,"dishDescribe":"海参口感软糯，冰镇后更加爽口，搭配特制蘸酱，别具风味。"},{"dishId":4,"dishImage":"dish04.jpg","dishName":"酱爆鱿鱼须","price":45.00,"dishStatus":0,"dtId":1,"dishDescribe":"鱿鱼须鲜嫩，酱爆后香味浓郁，口感劲道。"},{"dishId":5,"dishImage":"dish05.jpg","dishName":"凉拌海菜","price":32.00,"dishStatus":0,"dtId":1,"dishDescribe":"新鲜海菜搭配蒜末、辣椒油和香醋，清新爽口，富含碘元素。"},{"dishId":6,"dishImage":"dish06.jpg","dishName":"香菜拌海螺片","price":48.00,"dishStatus":0,"dtId":1,"dishDescribe":"海螺片鲜嫩，香菜提香，口感清爽。"},{"dishId":7,"dishImage":"dish07.jpg","dishName":"清蒸海鲈鱼","price":88.00,"dishStatus":0,"dtId":2,"dishDescribe":"选用新鲜海鲈鱼，肉质鲜嫩，清蒸保留了鱼的原汁原味，搭配姜丝和葱花。"},{"dishId":8,"dishImage":"dish08.jpg","dishName":"蒜蓉粉丝蒸扇贝","price":78.00,"dishStatus":0,"dtId":2,"dishDescribe":"扇贝鲜美多汁，粉丝吸收了蒜蓉和扇贝的鲜味，口感丰富。"},{"dishId":9,"dishImage":"dish09.jpg","dishName":"香辣蟹","price":128.00,"dishStatus":0,"dtId":2,"dishDescribe":"螃蟹肉质鲜美，配以香辣调料，辣而不燥，香气扑鼻。"},{"dishId":10,"dishImage":"dish10.jpg","dishName":"椒盐虾","price":98.00,"dishStatus":0,"dtId":2,"dishDescribe":"虾肉外酥里嫩，椒盐的香味与虾的鲜味完美融合，是下饭和下酒的绝佳选择。"},{"dishId":11,"dishImage":"dish11.jpg","dishName":"黑椒牛柳","price":108.00,"dishStatus":0,"dtId":2,"dishDescribe":"牛柳鲜嫩多汁，带子鲜美，搭配黑椒的浓郁香味。"},{"dishId":12,"dishImage":"dish12.jpg","dishName":"香煎银鲳鱼","price":98.00,"dishStatus":0,"dtId":2,"dishDescribe":"银鲳鱼肉质细嫩，香煎后外酥里嫩，搭配柠檬汁，清新解腻。"},{"dishId":13,"dishImage":"dish13.jpg","dishName":"姜葱炒花甲","price":68.00,"dishStatus":0,"dtId":2,"dishDescribe":"花甲肉鲜嫩，姜葱的香味去腥提鲜。"},{"dishId":14,"dishImage":"dish14.jpg","dishName":"干锅茶树菇","price":88.00,"dishStatus":0,"dtId":2,"dishDescribe":"茶树菇鲜香，鱿鱼劲道，干锅烹饪方式让食材更加入味。"},{"dishId":15,"dishImage":"dish15.jpg","dishName":"清蒸石斑鱼","price":158.00,"dishStatus":0,"dtId":2,"dishDescribe":"石斑鱼肉质鲜嫩，柠檬的清香去腥提鲜。"},{"dishId":16,"dishImage":"dish16.jpg","dishName":"辣炒蛤蜊","price":78.00,"dishStatus":0,"dtId":2,"dishDescribe":"蛤蜊鲜嫩多汁，辣炒后香气扑鼻，是下酒佳品。"},{"dishId":17,"dishImage":"dish17.jpg","dishName":"香煎带鱼","price":88.00,"dishStatus":0,"dtId":2,"dishDescribe":"带鱼外酥里嫩，搭配特制酱汁，口感丰富。"},{"dishId":18,"dishImage":"dish18.jpg","dishName":"蒜蓉蒸元贝","price":108.00,"dishStatus":0,"dtId":2,"dishDescribe":"元贝鲜美多汁，蒜蓉香味浓郁，口感细腻。"},{"dishId":19,"dishImage":"dish19.jpg","dishName":"海鲜豆腐汤","price":48.00,"dishStatus":0,"dtId":3,"dishDescribe":"汤中包含多种海鲜，如虾仁、鱿鱼、鱼丸等，搭配嫩滑的豆腐，汤汁鲜美。"},{"dishId":20,"dishImage":"dish20.jpg","dishName":"花旗参炖花胶","price":128.00,"dishStatus":0,"dtId":3,"dishDescribe":"花旗参滋补养生，花胶富含胶原蛋白，炖煮后汤汁清澈，口感醇厚。"},{"dishId":21,"dishImage":"dish21.jpg","dishName":"花蟹豆腐汤","price":158.00,"dishStatus":0,"dtId":3,"dishDescribe":"虫草花滋补，花蟹鲜美，炖煮后汤汁浓郁，口感鲜美。"},{"dishId":22,"dishImage":"dish22.jpg","dishName":"海带排骨汤","price":38.00,"dishStatus":0,"dtId":3,"dishDescribe":"海带富含营养，排骨鲜美，汤汁清淡，适合在饭前饮用。"},{"dishId":23,"dishImage":"dish23.jpg","dishName":"南瓜海鲜浓汤","price":58.00,"dishStatus":0,"dtId":3,"dishDescribe":"南瓜的香甜与海鲜的鲜美相结合，口感浓郁。"},{"dishId":24,"dishImage":"dish24.jpg","dishName":"玉米鲜虾汤","price":48.00,"dishStatus":0,"dtId":3,"dishDescribe":"玉米清甜，虾仁鲜嫩，汤汁清爽，营养丰富。"},{"dishId":25,"dishImage":"dish25.jpg","dishName":"冬瓜虾仁汤","price":42.00,"dishStatus":0,"dtId":3,"dishDescribe":"冬瓜清热解暑，虾仁鲜美，汤汁清淡，适合夏季饮用。"},{"dishId":26,"dishImage":"dish26.jpg","dishName":"菌菇海鲜汤","price":58.00,"dishStatus":0,"dtId":3,"dishDescribe":"多种菌菇搭配海鲜，鲜味浓郁，口感丰富。"},{"dishId":27,"dishImage":"dish27.jpg","dishName":"罗宋汤（海鲜版）","price":68.00,"dishStatus":0,"dtId":3,"dishDescribe":"经典的罗宋汤加入海鲜，口感浓郁，酸甜适中。"},{"dishId":28,"dishImage":"dish28.jpg","dishName":"海鲜炒饭","price":68.00,"dishStatus":0,"dtId":4,"dishDescribe":"米饭粒粒分明，搭配虾仁、鱿鱼、青豆等多种海鲜，口感丰富。"},{"dishId":29,"dishImage":"dish29.jpg","dishName":"海鲜意面","price":78.00,"dishStatus":0,"dtId":4,"dishDescribe":"意大利面口感劲道，搭配海鲜和浓郁的番茄酱或奶油酱。"},{"dishId":30,"dishImage":"dish30.jpg","dishName":"海鲜粥","price":58.00,"dishStatus":0,"dtId":4,"dishDescribe":"粥底细腻，加入虾仁、鱼片、瑶柱等海鲜，粥汁浓郁。"},{"dishId":31,"dishImage":"dish31.jpg","dishName":"海鲜焗饭","price":88.00,"dishStatus":0,"dtId":4,"dishDescribe":"米饭搭配丰富的海鲜，表面覆盖一层金黄的奶酪，焗烤后奶酪融化。"},{"dishId":32,"dishImage":"dish32.jpg","dishName":"海鲜烩饭","price":98.00,"dishStatus":0,"dtId":4,"dishDescribe":"米饭吸收了海鲜和蔬菜的鲜味，口感丰富。"},{"dishId":33,"dishImage":"dish33.jpg","dishName":"海鲜披萨","price":98.00,"dishStatus":0,"dtId":4,"dishDescribe":"经典的披萨加入虾仁、蟹肉、鱿鱼等海鲜，口感丰富。"},{"dishId":34,"dishImage":"dish34.jpg","dishName":"海鲜寿司拼盘","price":128.00,"dishStatus":0,"dtId":4,"dishDescribe":"包含多种海鲜寿司，如三文鱼寿司、金枪鱼寿司、虾寿司等。"},{"dishId":35,"dishImage":"dish35.jpg","dishName":"牛角海鲜面包","price":78.00,"dishStatus":0,"dtId":4,"dishDescribe":"新鲜面包搭配海鲜和奶酪，焗烤后外酥里嫩。"},{"dishId":36,"dishImage":"dish36.jpg","dishName":"海鲜烩面","price":88.00,"dishStatus":0,"dtId":4,"dishDescribe":"面条劲道，搭配海鲜和浓郁的汤汁，口感丰富。"},{"dishId":37,"dishImage":"dish37.jpg","dishName":"白米饭","price":3.00,"dishStatus":0,"dtId":4,"dishDescribe":"米饭颗粒分明，口感软糯，适合搭配各类海鲜菜肴。"},{"dishId":38,"dishImage":"dish38.jpg","dishName":"海鲜春卷","price":58.00,"dishStatus":0,"dtId":4,"dishDescribe":"春卷皮酥脆，内馅包含虾仁、鱿鱼等海鲜，口感丰富。"},{"dishId":39,"dishImage":"dish39.jpg","dishName":"芒果布丁","price":32.00,"dishStatus":0,"dtId":5,"dishDescribe":"芒果的香甜与布丁的嫩滑相结合，口感清新。"},{"dishId":40,"dishImage":"dish40.jpg","dishName":"椰汁西米露","price":28.00,"dishStatus":0,"dtId":5,"dishDescribe":"椰汁的清香与西米的爽滑相得益彰，搭配适量水果。"},{"dishId":41,"dishImage":"dish41.jpg","dishName":"水果拼盘","price":48.00,"dishStatus":0,"dtId":5,"dishDescribe":"精选新鲜水果，口感清新。"},{"dishId":42,"dishImage":"dish42.jpg","dishName":"红豆沙汤圆","price":28.00,"dishStatus":0,"dtId":5,"dishDescribe":"软糯的汤圆搭配香甜的红豆沙，口感甜蜜。"},{"dishId":43,"dishImage":"dish43.jpg","dishName":"提拉米苏","price":48.00,"dishStatus":0,"dtId":5,"dishDescribe":"经典的意大利甜品，咖啡与芝士的完美结合。"},{"dishId":44,"dishImage":"dish44.jpg","dishName":"芒果冰沙","price":32.00,"dishStatus":0,"dtId":5,"dishDescribe":"芒果打成冰沙，清凉解暑，口感细腻。"},{"dishId":45,"dishImage":"dish45.jpg","dishName":"抹茶红豆冰淇淋","price":32.00,"dishStatus":0,"dtId":5,"dishDescribe":"抹茶的清香与红豆的甜蜜相结合，口感细腻。"},{"dishId":46,"dishImage":"dish46.jpg","dishName":"水果塔","price":38.00,"dishStatus":0,"dtId":5,"dishDescribe":"酥脆的塔皮搭配新鲜水果，口感丰富。"},{"dishId":47,"dishImage":"dish47.jpg","dishName":"青岛啤酒","price":12.00,"dishStatus":0,"dtId":6,"dishDescribe":"清爽的啤酒，适合搭配海鲜。"},{"dishId":48,"dishImage":"dish48.jpg","dishName":"雪花啤酒","price":10.00,"dishStatus":0,"dtId":6,"dishDescribe":"清爽的啤酒，适合在用餐时饮用。"},{"dishId":49,"dishImage":"dish49.jpg","dishName":"茅台","price":2880.00,"dishStatus":0,"dtId":6,"dishDescribe":"高端白酒，适合商务宴请。"},{"dishId":50,"dishImage":"dish50.jpg","dishName":"五粮液","price":1580.00,"dishStatus":0,"dtId":6,"dishDescribe":"经典白酒，适合搭配海鲜。"},{"dishId":51,"dishImage":"dish51.jpg","dishName":"橙汁","price":12.00,"dishStatus":0,"dtId":6,"dishDescribe":"新鲜橙汁，口感清甜。"},{"dishId":52,"dishImage":"dish52.jpg","dishName":"苹果汁","price":10.00,"dishStatus":0,"dtId":6,"dishDescribe":"新鲜苹果汁，口感清甜。"},{"dishId":53,"dishImage":"dish53.jpg","dishName":"葡萄汁","price":12.00,"dishStatus":0,"dtId":6,"dishDescribe":"新鲜葡萄汁，口感清甜。"},{"dishId":54,"dishImage":"dish54.jpg","dishName":"绿茶","price":8.00,"dishStatus":0,"dtId":6,"dishDescribe":"清香的绿茶，适合在用餐前后饮用。"},{"dishId":55,"dishImage":"dish55.jpg","dishName":"红茶","price":8.00,"dishStatus":0,"dtId":6,"dishDescribe":"醇厚的红茶，适合搭配甜品。"},{"dishId":56,"dishImage":"dish56.jpg","dishName":"乌龙茶","price":10.00,"dishStatus":0,"dtId":6,"dishDescribe":"香气浓郁的乌龙茶，适合在用餐前后饮用。"},{"dishId":57,"dishImage":"dish57.jpg","dishName":"可口可乐","price":10.00,"dishStatus":0,"dtId":6,"dishDescribe":"经典的碳酸饮料，适合在用餐时饮用。"},{"dishId":58,"dishImage":"dish58.jpg","dishName":"雪碧","price":10.00,"dishStatus":0,"dtId":6,"dishDescribe":"清爽的碳酸饮料，适合在用餐时饮用。"},{"dishId":59,"dishImage":"dish59.jpg","dishName":"气泡水","price":12.00,"dishStatus":0,"dtId":6,"dishDescribe":"清新爽口的气泡水，适合搭配海鲜。"},{"dishId":60,"dishImage":"dish60.jpg","dishName":"红酒（干红）","price":188.00,"dishStatus":0,"dtId":6,"dishDescribe":"经典红酒，适合搭配海鲜焗饭、海鲜烩饭等。"},{"dishId":61,"dishImage":"dish61.jpg","dishName":"白酒（高度）","price":288.00,"dishStatus":0,"dtId":6,"dishDescribe":"高度白酒，适合搭配香辣蟹、蒜蓉粉丝蒸扇贝等。"}]
  }
};

export const refundApi = {
  getRefundDTOByRefundId : (rrId) =>{
    return request({
      url: `/refundDTO/refund-detail/${rrId}`,
      method: 'GET'
    })
  },
  listRefundDTO : () =>{
    return request({
      url: `/refundDTO/list`,
      method: 'GET'
    })
  },
  updateRefund: (data) => {
    return request({
      url: '/refund-request/update',
      method: 'POST',
      data
    })
  },
  processRefund: (data) => {
    return request({
      url: '/refund-request/process-refund',
      method: 'POST',
      data
    })
  }
}
